package UIFree.graphicTools.color.palettes
{
	import UIFree.uif_component;
	
	import UIUtils.uif_color;
	
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class uif_RGBPaletteView extends uif_basePaletteView {
		public function uif_RGBPaletteView(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
		}
		
		override protected function drawPalette(a_bmd: BitmapData): void {
			function ccos(i: Number, light: Number=1): uint {
				var c: Number = (Math.cos(i * Math.PI * 2) + 1) / 2;
				if (light >= 0.5) 
					return Math.floor(c * 0xFF * (1 - light) * 2);
				else return Math.floor(c * 0xFF * light * 2 + 0xFF * (1 - light * 2));
			}
			
			var r: Rectangle = new Rectangle(0, 0, 4, 4);
			
			while (r.y < a_bmd.height) {
				r.x = 0;
				while (r.x < a_bmd.width) {
					var i: Number = r.x / a_bmd.width;
					var l: Number = r.y/a_bmd.height;
					var color: uint = uif_color.RGB(ccos(i, l),
													ccos(i + 1/3 * 2, l),
													ccos(i + 1/3, l));
					a_bmd.fillRect(r, color);
					r.x += r.width;
				}
				r.y += r.height;
			}
		}
	}
}